package com.lswms.controller;

import com.lswms.annotation.Login;
import com.lswms.annotation.LoginUser;
import com.lswms.common.page.PageInfo;
import com.lswms.common.page.PageRequest;
import com.lswms.common.utils.Result;
import com.lswms.common.validator.ValidatorUtils;
import com.lswms.dto.vo.req.DeleteMyNumsReq;
import com.lswms.dto.vo.req.DoubleBallDetailReq;
import com.lswms.dto.vo.req.HistoryOpenReq;
import com.lswms.dto.vo.req.MyLotteryTicketReq;
import com.lswms.dto.vo.req.MyNumsReq;
import com.lswms.dto.vo.req.PayReq;
import com.lswms.dto.vo.req.QuerySignInfoReq;
import com.lswms.dto.vo.req.RandomNumlReq;
import com.lswms.dto.vo.req.SaveDataReq;
import com.lswms.dto.vo.req.SaveNumReq;
import com.lswms.dto.vo.req.SetXCountReq;
import com.lswms.dto.vo.req.SignListReq;
import com.lswms.dto.vo.req.SignReq;
import com.lswms.dto.vo.resp.LotteryInfoResp;
import com.lswms.dto.vo.resp.LotteryListResp;
import com.lswms.dto.vo.resp.MyNumsResp;
import com.lswms.dto.vo.resp.NewOpenLotteryResp;
import com.lswms.dto.vo.resp.QuerySignDetailResp;
import com.lswms.dto.vo.resp.SignListResp;
import com.lswms.dto.vo.resp.TradeListResp;
import com.lswms.entity.YnUserEntity;
import com.lswms.service.YnLotteryRecordService;
import com.lswms.service.YnLotteryService;
import com.lswms.service.YnLotteryTicketActivityService;
import com.lswms.service.YnLotteryTicketOrderService;
import com.lswms.service.YnLotteryTicketResultService;
import com.lswms.service.YnSignRecordService;
import com.lswms.service.YnSignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import springfox.documentation.annotations.ApiIgnore;

import com.alibaba.fastjson.JSON;

/**
 * 彩票接口
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2020-05-06
 */
@RestController
@RequestMapping("/api/ticket")
@Api(tags="彩票接口")
@Slf4j
public class YnLotteryTicketController {

	@Autowired
	private YnLotteryTicketActivityService yYnLotteryTicketActivityService;
	
	@Autowired
	private YnLotteryTicketResultService ynLotteryTicketResultService;
	
	@Autowired
	private YnLotteryTicketOrderService ynLotteryTicketOrderService;

	

	
    /**
     * 首页弹框
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("indexNewReward")
    @ApiOperation("首页弹框")
    @Login
    public Result<Object> querySign(@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
        return new Result<Object>().ok(yYnLotteryTicketActivityService.queryIndexNewReward(ynuser));
    }
    
    /**
     * 首页弹框领取奖励
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("receiveNewReward")
    @ApiOperation("首页弹框领取奖励")
    @Login
    public Result<Object> receiveNewReward(@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
    	yYnLotteryTicketActivityService.receiveNewReward(ynuser);
        return new Result<Object>();
    }
    /**
     * 测试今天运势
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("forecastLuck")
    @ApiOperation("测试今天运势")
    @Login
    public Result<Object> forecastLuck(@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
        return new Result<Object>().ok(yYnLotteryTicketActivityService.forecastLuck(ynuser));
    }

    
    /**
     * 双色球、排列五详情页
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("doubleBallDetail")
    @ApiOperation("双色球、排列五详情页")
    public Result<NewOpenLotteryResp> doubleBallDetail(@RequestBody DoubleBallDetailReq req,HttpServletRequest request){
        return new Result<NewOpenLotteryResp>().ok(ynLotteryTicketResultService.doubleBallDetail(req));
    }
    
    /**
     * 随机号码
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("randomNum")
    @ApiOperation("随机号码")
    @Login
    public Result<Object> randomNum(@RequestBody RandomNumlReq req,HttpServletRequest request){
        return new Result<Object>().ok(yYnLotteryTicketActivityService.randomNum(req));
    }

    /**
     * 保存号码
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("saveNum")
    @ApiOperation("保存号码")
    @Login
    public Result<Object> saveNum(@RequestBody SaveNumReq req,@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
        return new Result<Object>().ok(ynLotteryTicketOrderService.saveNum(req,ynuser));
    }

    /**
     * 支付
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("pay")
    @ApiOperation("支付")
    @Login
    public Result<Object> pay(@RequestBody PayReq req,@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
    	ynLotteryTicketOrderService.pay(req,ynuser);
        return new Result<Object>();
    }

    /**
     * 修改倍数
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("setXCount")
    @ApiOperation("修改倍数")
    @Login
    public Result<Object> setXCount(@RequestBody SetXCountReq req,@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
    	ynLotteryTicketOrderService.setXCount(req,ynuser);
        return new Result<Object>();
    }
    
    /**
     * 最新开奖
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("newOpenLottery")
    @ApiOperation("最新开奖")
    public Result<Object> newOpenLottery(HttpServletRequest request){
        return new Result<Object>().ok(ynLotteryTicketResultService.newOpenLottery());
    }
    /**
     * 历史开奖
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("historyOpenLottery")
    @ApiOperation("历史开奖")
    public Result<PageInfo<NewOpenLotteryResp>> historyOpenLottery(@RequestBody HistoryOpenReq req,HttpServletRequest request){
    	PageInfo<NewOpenLotteryResp> resp = ynLotteryTicketResultService.historyOpenLottery(req);
        return new Result<PageInfo<NewOpenLotteryResp>>().ok(resp);
    }
    
    /**
     * 我的选号
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("myNums")
    @ApiOperation("我的选号")
    @Login
    public Result<PageInfo<MyNumsResp>> myNums(@RequestBody MyNumsReq dto,@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
    	PageInfo<MyNumsResp> resp = ynLotteryTicketOrderService.myNums(dto,ynuser);
    	return new Result<PageInfo<MyNumsResp>>().ok(resp);
    }

    /**
     * 我的选号删除
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("deleteMyNums")
    @ApiOperation("我的选号删除")
    @Login
    public Result<Object> deleteMyNums(@RequestBody DeleteMyNumsReq dto,@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
    	ynLotteryTicketOrderService.deleteMyNums(dto,ynuser);
    	return new Result<Object>();
    }

    /**
     * 我的彩票
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("myLotteryTicket")
    @ApiOperation("我的彩票")
    @Login
    public Result<PageInfo<MyNumsResp>> myLotteryTicket(@RequestBody MyLotteryTicketReq dto,@ApiIgnore @LoginUser YnUserEntity ynuser,HttpServletRequest request){
    	PageInfo<MyNumsResp> resp = ynLotteryTicketOrderService.myLotteryTicket(dto,ynuser);
    	return new Result<PageInfo<MyNumsResp>>().ok(resp);
    }
    
    /**
     * banner、喜报
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("indexData")
    @ApiOperation("banner、喜报")
    public Result<Object> indexData(HttpServletRequest request){
    	return new Result<Object>().ok(ynLotteryTicketResultService.indexData());
    }

    /**
     * 每日数据
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("todayData")
    @ApiOperation("每日数据")
    public Result<Object> todayData(HttpServletRequest request){
    	String s = request.getParameter("s");
    	String e = request.getParameter("e");
    	return new Result<Object>().ok(ynLotteryTicketResultService.todayData(s,e));
    }


}